package com.caigou.controller;

import com.caigou.bean.exam.entity.Users;
import com.caigou.bean.param.WxAuthParam;
import com.caigou.bean.vo.AuthLoginTokenVO;
import com.caigou.security.utils.CurrentUser;
import com.caigou.service.IAuthSignInService;
import com.caigou.util.Result;
import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.request.AuthRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/wx")
public class AuthController {

    @Resource
    private IAuthSignInService authSignInService;


    /**
     * 获取微信授权码
     * @return
     */
    @PostMapping("/authSignIn")
    public Result<String> weChatAuthSignIn() {
        return authSignInService.weChatAuthSignIn();

    }

    /**
     * 根据授权码获取登录信息
     * @param callback
     * @return
     */
    @RequestMapping("/wxUserInfo")
    public Result<Object> login(AuthCallback callback) {
        log.info("接受到的参数={}",callback);
        return authSignInService.getAuthResponse(callback);


    }

    /**
     * 根据用户信息获取登录token
     * @param param
     * @return
     */
    @RequestMapping("/token/auth")
    public Result<AuthLoginTokenVO> authWxLoginToken(@RequestBody WxAuthParam param) {
        return authSignInService.authWxLoginToken(param);
    }


    /**
     * 用户绑定微信信息
     * @param param
     * @return
     */
    @RequestMapping("/binding/wx/auth")
    public Result<AuthLoginTokenVO> bindingWxUserInfo(@RequestBody WxAuthParam param) {
        return authSignInService.bindingWxUserInfo(param);
    }


}
